package cn.ycl.system.other.study.leetCode.deepFirstSort;

/**
 * @author YT-007
 */
public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    public static void main(String[] args) {
//        TreeNode treeNode7 = new TreeNode(7);
//        TreeNode treeNode6 = new TreeNode(6);
//        TreeNode treeNode5 = new TreeNode(5);
//        TreeNode treeNode4 = new TreeNode(4);
//        TreeNode treeNode3 = new TreeNode(3, treeNode6, treeNode7);
//        TreeNode treeNode2 = new TreeNode(2, treeNode4, treeNode5);
//        TreeNode treeNode1 = new TreeNode(1, treeNode2, treeNode3);
         TreeNode treeNode7 = new TreeNode(7);
         TreeNode treeNode6 = new TreeNode(6);
         TreeNode treeNode5 = new TreeNode(5);
         TreeNode treeNode4 = new TreeNode(4,null , null);
         TreeNode treeNode3 = new TreeNode(3, treeNode6, treeNode7 );
         TreeNode treeNode2 = new TreeNode(2, treeNode4, treeNode5);
         TreeNode treeNode1 = new TreeNode(1, treeNode2, treeNode3);
        invertTree(treeNode1);
//        pre(treeNode1);
//        System.out.println();
//        mid(treeNode1);
//        System.out.println();
//        tail(treeNode1);

    }

    public static void pre(TreeNode root) {
        if (root == null) {
            return;
        }
        System.out.print(root.val + " ");
        pre(root.left);
        pre(root.right);
    }

    public static void mid(TreeNode root) {
        if (root == null) {
            return;
        }
        mid(root.left);
        System.out.print(root.val + " ");
        mid(root.right);
    }

    public static void tail(TreeNode root) {
        if (root == null) {
            return;
        }
        tail(root.left);
        tail(root.right);
        System.out.print(root.val + " ");
    }
    public static TreeNode invertTree(TreeNode root) {
        //看见这题，我脑海中马上想起了【101】对称二叉树
        if(root == null){
            return null;
        }
        TreeNode left = invertTree(root.left);
        TreeNode right = invertTree(root.right);
        root.left = right;
        root.right = left;
        return root;

    }
}